/*
	isnum XFCN
	2 Mar 1989 Greg Jorgensen, Mac DTS
	й Apple Computer Inc., 1989
	
	usage: isnum(value)
	
	returns: true if value contains a valid number, false otherwise
	
	value must contain only digits (0-9), and one '-' and one '.'
	the '-' must be the first character, if present
	
*/

#include <MacTypes.h>
#include <SetUpA4.h>
#include <strings.h>
#include "HyperXCmd.h"

/* Hypercard parameter block:

	typedef struct XCmdBlock {
		short	paramCount;     
	    Handle  params[16];
	    Handle  returnValue;      
	    Boolean	passFlag; 
	      
	    void	(*entryPoint)();
	    short	request;  
	    short	result;  
	    long	inArgs[8];
	    long	outArgs[4];
	   } XCmdBlock, *XCmdBlockPtr;
*/

/* еее */

pascal void main(paramPtr)
	XCmdBlockPtr	paramPtr;
{
	register	char	*s;
	int					f,d;
	
	RememberA0();					/* A0 points to this procedure */
	SetUpA4();						/* point A4 at this proc for literals */
	
	paramPtr->returnValue = NewHandle(6L);
	HLock(paramPtr->returnValue);
	strcpy(*(paramPtr->returnValue), "false");
	
	if (paramPtr->paramCount == 1) {
		HLock(paramPtr->params[0]);
		s = *(paramPtr->params[0]);
		f = 1;						/* true if numeric */
		d = 0;						/* decimal points found */
		
		if (*s == '-')				/* starts with minus? */
			s++;

		for (; *s != '\0'; s++) {
			if (*s < '0' || *s > '9') {
				d += (*s == '.');	/* count decimals */
				if (d != 1) {
					f = 0;
					break;
				}
			}
		}
		
		HUnlock(paramPtr->params[0]);
		if (f == 1)
			strcpy(*(paramPtr->returnValue), "true");
	}
	HUnlock(paramPtr->returnValue);
	RestoreA4();					/* point A4 back to where it was */
}

#include "XCmdGlue.inc.c"
